package com.fly.msg;

import com.google.common.collect.Lists;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

import static com.fly.msg.Constant.TOPIC_MESSAGE_ADDRESS;
import static com.fly.msg.Constant.WS_CLIENT_SEND_ADDRESS;

/**
 * @author frinder
 * @date 2018/6/1
 * @Description: ${todo}
 */
@Controller
public class WsController {

    @Resource
    WebSocketService webSocketService;

    @MessageMapping(WS_CLIENT_SEND_ADDRESS)
    @SendTo(TOPIC_MESSAGE_ADDRESS)
    public WiselyResponse call(WiselyMessage message) throws Exception {
        List<String> users = Lists.newArrayList();
        users.add("admin");
        webSocketService.send(users, new WiselyResponse("admin hello"));

        return new WiselyResponse("Welcome, " + message.getName() + "!");
    }

}
